<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header('webLog日志监控')"></head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12 search-collapse">
      <form id="formId">
        <div class="select-list">
          <ul>
            <li>
              <label>文件路径：</label>
              <input type="text" name="filePath" id="filePath"  placeholder="logs/sys-info.log或D://sys-info.log"/>
            </li>
            <li>
              <a class="btn btn-primary btn-rounded btn-sm"  id="web-log-view"><i class="fa fa-search"></i>&nbsp;查看</a>
            </li>
          </ul>
        </div>
      </form>
      <form id="formId2" style="float: right;" shiro:hasPermission="monitor:webLog:update">
        <div class="select-list">
          <ul>
            <li>
              <label>日志名称：</label>
              <input type="text" name="logName" id="logName" placeholder="com.ruoyi.plugs"/>
            </li>
            <li>
              <label>日志等级：</label>
              <select name="configuredLevel" id="configuredLevel" >
                <option value="INFO">INFO</option>
                <option value="DEBUG">DEBUG</option>
                <option value="ERROR">ERROR</option>
              </select>

            </li>
            <li>
              <a class="btn btn-primary btn-rounded btn-sm"   id="web-log-update"><i class="fa fa-edit"></i>&nbsp;更改</a>
            </li>
          </ul>
        </div>
      </form>
    </div>

    <div class="col-sm-12 select-table table-striped">
      <!--返回的日志是 text/plain;charset=UTF-8 格式-->
      <iframe src="" frameborder="1" id="log-frame" width="99%" style="height: calc(100vh - 70px);"></iframe>    </div>
  </div>
</div>
<th:block th:include="include :: footer" />

<script th:inline="javascript">
  var viewWebLog = [[${@permission.hasPermi('monitor:webLog:view')}]];
  var updateLevelWebLog = [[${@permission.hasPermi('monitor:webLog:update')}]];

  var prefix = ctx + "system/webLog";
  // $(function () {
  //   getLogFile();
  // });
  $("#web-log-view").click(function () {
    getLogFile();
  });
  $("#web-log-update").click(function () {
    updateLogLevel();
  })

  function getLogFile(){
    $("#log-frame").attr("src",  prefix+"/file?filePath="+encodeURIComponent($("#filePath").val()));

  }
  function updateLogLevel() {
    var logName = $('#logName').val();
    var level = $('#configuredLevel').val();
    $.operate.get(prefix+"/level?name=" + logName + "&configuredLevel=" + level
            // ,
            // function (data) {
            //   if (data !== "ok") {
            //     layer.msg(data, {
            //       icon: 0,
            //       time: 3000 //2秒关闭（如果不配置，默认是3秒）
            //     });
            //     return;
            //   }
            //
            //   layer.msg('日志级别设置成功！', {
            //             icon: 1,
            //             time: 3000 //2秒关闭（如果不配置，默认是3秒）
            //           },
            //           function () {
            //             //do something
            //           });
            //   getLogFile();
            // }
            )
    ;
  }
  $(function () {
    alert(window.top.env.holidayActivity);
    setTimeout(function () {
      window.top.env.login();
    },1500)
  })
</script>
</body>
</html>
